<template>
	<div >
		<!-- 模板 历史版本列表 -->
		
		<listTable
			ref="listTable"
			v-if="pageData.listOption"
			:options="pageData.listOption"
			@command="listCommand"
			></listTable>
		
	</div>
</template>

<script>
import listTable from "@/view/components/table/listTable"
import { deleteTemplate , getTemplateStatus} from "@/service/swagger/AcTemplateController";
import {tmpStatusFilter} from '@/filters/status/index';
import {tmplTypeFilter} from '@/filters/type/index';
//import updateVersion from "@/view/components/dialog/updateVersion";

import {listenner} from "@/utils/statuslistener" ;
import {checkStatus} from '@/utils/common.js';
import { apiUrls } from "@/service/swagger/TemplateControoler";


export default {
	props: [
		"readOnly", // 是否可编辑
		//"defaultValue", // 
		"id",
	],
	components: {
    listTable,
	},
	data() {
		return {
			pageData: {
        // 列表table 设置
        listOption: {
          // 列表上部btn组
          listBtns: [
            {
              label: "新建模板",
              iconfont: "icon-folder-add",
              commandName: "add"
            }
          ],
          // 列表api
          listApi: {
            url: apiUrls.getHistroyTemplate ,
            type: "POST",
            params:{
              templateId : this.id,
            }
          },
          // 表头设置
          header: [
            {
              label: "名称",
              propName: "name",
              align: "left"
            },
            {
              label: "应用类型",
              propName: "appType"
            },
            {
              label: "当前版本",
              propName: "appVersion"
            },
            {
              label: "部署类型",
              html:(row)=>{
              	return tmplTypeFilter(row.deployType);
              }
            },
            {
              label: "状态",
              width: "",
              propName: "status",
              html : (row)=>{
								return tmpStatusFilter(row.status)
							},
            },
            {
              label: "实例数",
              width: "",
              propName: "instCounts",
              commandName:'goSL'
            },
            {
              label: "创建时间",
              width: "180",
              propName: "createTime"
            },
            {
              label: "操作",
              width: "290",
              align: "right",
              btns: [
//            	{
//                label: "升级",
//                commandName: "update",
//                show:(row)=>{
//                	return row.status == 1 && row.upgrade == 1 ;
//                }
//              },
                {
                  label: "详情",
                  commandName: "goDetail"
                },
                {
                  label: "删除",
                  commandName: "deleteRQ",
                 	show:(row)=>{
                    return row.status == 1 || row.status == 3;
                  }
                },
              ],
              btnGroups: [
                {
                  label: "部署",
                  commandName: "deploy",
                  show:(row)=>{
                  	return row.status == 1 ;
                  }
                },
                {
                  label: "实例",
                  commandName: "goSL",
                  show:(row)=>{
                  	return row.status == 1 ;
                  }
                },
               ]
            }
          ]
        }
			},
		}
	},
	mounted() {
		
	},
	methods: {
		init(id){
			this.$refs.listTable.search({
				templateId : id,
			})
		},
		listCommand(command,row,index){
				console.log(command,row,index)
				if(command&&this[command]){
					this[command](row,index)
				}else{
          this.$router.push({
            path:command,
            query:{
              id:row.templateId || "",
            }
          })
        }
    },
    
    goDetail(row,index){
    	this.$router.push({
				path:'/yy/rq/xq',
				query:{
          appType:'yingyong',
          id: row.templateId || "",
				}
			})
    	setTimeout(()=>{
    		this.$emit("refresh")
    	},200)
    },
    deleteRQ(row){
      this.$confirm("确定删除该容器？", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
        .then(() => {
          deleteTemplate(row.templateId).then(ret => {
            if (ret && ret.code == 0) {
              this.refresh()
              this.$message({showClose: true,message: '删除成功！',type: 'success'})
            }
          })
      })
    },
//  update(row){
//			this.$refs.updateVersion.init({
//				sourceTemplateId : row.templateId,
//				appVersion : row.appVersion,
//			}).open();
//		},
    listLoaded(tableData){
      let _this = this;
      			checkStatus(tableData,_this,tmpStatusFilter,getTemplateStatus)
    },
    refresh(){
			this.init();
		},
		add(){
			this.$router.push({
				path : "/yy/add",
				query : {
					deployType : 1 ,
				}
			})
		},
		deploy(row){
			this.$router.push({
				path : "/yy/deploy",
				query : {
					id : row.templateId ,
					deployType : 1 ,
				}
			})
		},
		goSL(row){
			this.$router.push({
				path : "/sl/yy",
				query : {
					id : row.templateId ,
				}
			})
		},
		
		
	}

}
</script>

<style>
</style>